package com.burges.net.ml.recommendationAlgorithm

import org.apache.flink.api.scala.{DataSet, ExecutionEnvironment}
import org.apache.flink.ml.common.ParameterMap
import org.apache.flink.ml.recommendation.ALS

/**
  * 创建人    BurgessLee 
  * 创建时间   2020/2/27 
  * 描述      推荐算法使用代码示例ALS
  */
object ALSDemo {

	def main(args: Array[String]): Unit = {
		val environment = ExecutionEnvironment.getExecutionEnvironment
		//读取训练数据集
		val trainingDs: DataSet[(Int, Int, Double)] = environment.fromElements((1, 1, 1.0))
		//读取测试数据集
		val testingDs: DataSet[(Int, Int)] = environment.fromElements((1,1))
		//设定ALS学习器
		val als: ALS = ALS()
				.setIterations(100)
				.setNumFactors(10)
				.setBlocks(100)
				.setTemporaryPath("hdfs://temporary/Path")
		//通过ParameterMap计算额外参数
		val parameterMap = ParameterMap()
        		.add(ALS.Lambda, 0.9)
        		.add(ALS.Seed, 42L)
		//计算隐式分解
		als.fit(trainingDs, parameterMap)
		//根据测试数据集，计算推荐结果
		val result: DataSet[(Int, Int, Double)] = als.predict(testingDs)

	}

}
